Docker build失敗跳出killed

睡睡唸

內部要搞一個AI的開發平臺,
所以我負責python的負載平衡架構,
因爲他的程式開發好像有點困難,就用nginx的LB來做了。

正文

驗證169. Nginx的負載平衡時,需要讓範例程式顯示一下請求的資訊,
確認真的有做到這塊。

打包以前的舊AI程式時就暴掉了,
出現 killed的error。

> [6/8] RUN pip3 install torch torchvision torchaudio --index-url [https://download.pytorch.org/whl/cpu](https://download.pytorch.org/whl/cpu "https://download.pytorch.org/whl/cpu"):

1.293 Looking in indexes: [https://download.pytorch.org/whl/cpu](https://download.pytorch.org/whl/cpu "https://download.pytorch.org/whl/cpu") 2.901 Collecting torch 2.917 Downloading [https://download.pytorch.org/whl/cpu/torch-2.0.1%2Bcpu-cp38-cp38-linux_x86_64.whl](https://download.pytorch.org/whl/cpu/torch-2.0.1%2Bcpu-cp38-cp38-linux_x86_64.whl "https://download.pytorch.org/whl/cpu/torch-2.0.1%2Bcpu-cp38-cp38-linux_x86_64.whl") (195.4 MB) 11.30 Killed ------ Dockerfile:25 -------------------- 23 | RUN apt-get update && apt-get install -y enchant && apt-get install -y python3.7 python3-pip libgl1 && apt-get clean && rm -rf /var/lib/apt/lists/* 24 | RUN pip3 install --upgrade pip 25 | >>> RUN pip3 install torch torchvision torchaudio --index-url [https://download.pytorch.org/whl/cpu](https://download.pytorch.org/whl/cpu "https://download.pytorch.org/whl/cpu") 26 | RUN pip3 install paddlepaddle==2.4.2 -i [https://mirror.baidu.com/pypi/simple](https://mirror.baidu.com/pypi/simple "https://mirror.baidu.com/pypi/simple") 27 | RUN pip3 install --no-cache-dir -r requirements.txt -------------------- ERROR: failed to solve: process "/bin/sh -c pip3 install torch torchvision torchaudio --index-url [https://download.pytorch.org/whl/cpu](https://download.pytorch.org/whl/cpu "https://download.pytorch.org/whl/cpu")" did not complete successfully: exit code: 137

查了一下,說是因爲記憶體不足導致docker build的時候暴掉。
ref. PyTorch Docker build error

`Killed` means that the compiler was killed by the kernel because it used too much memory. There are a few workarounds:

- increase the memory limit for docker container
- limit the number of concurrent builds by changing the `Dockerfile` to include `MAX_JOBS=1` [here](https://github.com/pytorch/pytorch/blob/master/docker/pytorch/Dockerfile#L30)

把我的docker resource 的記憶體資源加大後就好了(我mac記憶體只有16G)。

[[168-fig.1.jpg]]